package chenjiuxu.seniorui.study;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by 15705 on 2017/12/25.
 * -环形渲染
 */

public class RadialGradientView extends View {
    private final Paint paint;

    public RadialGradientView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint();
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int w = getWidth() / 2;
        int[] colors = new int[]{Color.BLACK, Color.RED, Color.WHITE, Color.BLUE};
        float[] positions = null;
        RadialGradient radialGradient = new RadialGradient(w, w, w, colors, positions, Shader.TileMode.CLAMP);
        paint.setShader(radialGradient);
        canvas.drawCircle(w, w, w, paint);
    }
}
